import React from 'react'
import ReactDOM from 'react-dom'   
import './css/MemberList.css'
import * as DataHandler from './DataHandler'
import  List from '../../component/List/List'//list
import othericon from './assets/MemberList/other.png'
import arricon from './assets/MemberList/pic.png'


class MemberList extends React.Component {
     listConfig = {
        width:  350,         
        theme:'default',   
        dataConfig:[ {
                key:'icon',
                itemStyle:{width:35,   }  ,
                  itemClick:(e,data)=>{  
                }             
            },{
                key:'name',
                itemStyle:{  marginLeft:'10px' },
                 itemClick:(e,data)=>{  
                }            
            },{
                key:'del',
                download:true, 
                itemStyle:{    position: 'absolute',  right: '10px' ,color:'red' },
                itemClick:(e,data)=>{ 
                    let list=[];
                    this.listData.map((item,i)=>{
                        if(item.user_id!=data.user_id){
                            list.push(item);
                        }
                    });
                    this.listData=list;
                    let uid=[];
                    this.listData.map((item,i)=>{
                        uid.push(item.user_id)
                    })
                    let par={
                        'msg_id':T.data('msg_id'),
                        'user_id':uid.toString()
                    } 
                    T.ajax({
                        key: 'u-msg-user-rel',
                        data: par, 
                        success: function success(result) {  
                            //删除成功后，不默认跳转
                            // T.router.go('/ChatInterface');//跳转到聊天页面 
                            // 清空
                        }
                    }); 
                    this.setState({})
                }          
            }
        ]
    }
 
    listData=[
        {
            name:"王默认",
            del:"删除",   
            icon:othericon,
            id:1,
            href:"#"
        },
        {
            name:"李沟通",
            del:"删除",   
            icon:othericon,
            id:2
        }
    ] 

    info={
        searchWord:''
    }

     componentWillMount = () => {
 
    } 
    componentDidMount = () => { 
        //    let type ='man';
          let type = T.data('listType');
            switch(type){
                case 'man'://成员
                    let manData =T.data('msg_user');
                    this.listData =[];
                    manData.map((item,i)=>{
                        item.name =item.user_name;
                        item.del ="删除"; 
                        item.icon=othericon;
                        item.itemClick=(e,data)=>{
                             let list=[];
                            this.listData.map((item,i)=>{
                                if(item.id!=data.id){
                                    list.push(item);
                                }
                            });
                            this.listData=list;
                            this.setState({})
                        }      
                    })

                    this.listConfig.dataConfig[2].download=false;
                    this.listData =manData;
                    this.setState({})
                    
                break;
                case 'arr'://列表
                     let arrData =T.data('att_list');
                    this.listData =[];
                    arrData.map((item,i)=>{
                        item.name =item.filetile;
                        item.del ="下载"; 
                        item.filepath=item.filepath;
                        item.href=item.filepath;
                        item.filetype=item.filetype;
                        item.icon=arricon;
                        item.itemClick=()=>{
                            // console.log('s')
                        }  
                    })
                    this.listConfig.dataConfig[2].download=true; 
                    this.listData =arrData ;
                   this.setState({})
                    
                break;
            }
        T.on('dc_listType',(obj)=>{
            switch(obj.new){
                case 'man'://成员
                    let manData =T.data('msg_user');
                    this.listData =[];
                    manData.map((item,i)=>{
                        item.name =item.user_name;
                        item.del ="删除";
                        item.icon=othericon;
                        item.itemClick=(e,data)=>{
                             let list=[];
                            this.listData.map((item,i)=>{
                                if(item.id!=data.id){
                                    list.push(item);
                                }
                            });
                            this.listData=list;
                            this.setState({})
                        }      
                    })
                    this.listConfig.dataConfig[2].download=false; 
                    this.listData =manData;
                break;
                case 'arr'://列表
                     let arrData =T.data('att_list');
                    this.listData =[];
                    arrData.map((item,i)=>{
                        item.name =item.filetile;
                        item.del ="下载";
                        item.download=true; 
                        item.filepath=item.filepath;
                        item.href=item.filepath;
                        item.filetype=item.filetype;
                        item.icon=arricon;
                        item.itemClick=()=>{
                            // console.log('s')
                        }  
                    })
                    this.listConfig.dataConfig[2].download=true; 
                    this.listData =arrData 
                break;
            }
            this.setState({})
        })  
    } 

    info={
        // boxW:360,
    }
    backFn=()=>{
        T.router.go('/ChatInterface');//跳转到聊天页面 
    }
    render() {
        return (
            <div  className="MemberList"> 
                <div className="ret" onClick={this.backFn} ><label className="lab" >《 返回聊天界面</label></div> 
                 <List ref='list' listConfig={this.listConfig}  listData={this.listData} ></List>
            </div>
        )
    }
} 
export default MemberList 